from connector.DatabaseDriver import DatabaseDriver


# 根据用户名获取用户
def get_user_by_username(driver: DatabaseDriver, username):
    return driver.select_one(sql='select * from user where user_name="{}"'.format(username))


# 根据用户名和密码获取用户，登录的时候需要
def get_user_by_username_and_password(driver: DatabaseDriver, username, password):
    return driver.select_one(
        sql='select * from user where user_name="{}" and user_password="{}"'.format(username, password))


# 注册用户， 需要用户名、用户密码、用户角色
def register_user(driver: DatabaseDriver, username, password, user_role):
    return driver.insert(
        sql='insert into user(user_name, user_password,user_role) values ("{}","{}","{}")'.format(username, password,
                                                                                                  user_role))
